package com.efast.dmom.mgmt.service.les.impl;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.bean.les.ImmediateReplenishmentByLibraryBean;
import com.efast.dmom.mgmt.bean.les.ImmediateReplenishmentByRequestBean;
import com.efast.dmom.mgmt.bean.les.WindowReplenishmentBean;
import com.efast.dmom.mgmt.entity.les.*;
import com.efast.dmom.mgmt.service.les.TeKittingWmsConfirmService;
import com.efast.dmom.mgmt.service.les.TtWhmStockOutboundService;
import com.efast.dmom.mgmt.service.les.TwBasDpathWindowTimeService;
import com.efast.dmom.mgmt.service.les.TwBasPackSkuQtyService;
import com.efast.dmom.mgmt.service.les.TwInvPacktranDetailService;
import com.efast.dmom.mgmt.service.les.TwInvPacktranHeaderService;
import com.efast.dmom.mgmt.service.les.TwInvPalMriService;
import com.efast.dmom.mgmt.service.les.WindowReplenishmentByCumulativeConsumptionJobService;
import com.efast.dmom.mgmt.utils.Assist;

import com.efast.dmom.mgmt.utils.MesConstant;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 窗口补货 ：Window replenishment 累计消耗： Cumulative consumption 窗口补货-按累计消耗
 * 
 * @author Administrator
 */
@Service
public class WindowReplenishmentByCumulativeConsumptionJobServiceImpl
		implements WindowReplenishmentByCumulativeConsumptionJobService {

	/**
	 *
	 * 补货任务需求 TW_INV_PAL_MRI
	 */
	@Autowired
	private TwInvPalMriService twInvPalMriService;
	/**
	 *
	 * 补货余量需求 TW_BAS_PACK_SKU_QTY
	 */
	@Autowired
	private TwBasPackSkuQtyService twBasPackSkuQtyService;
	/**
	 *
	 * 实际窗口时间 TW_BAS_DPATH_WINDOW_TIME
	 */
	@Autowired
	private TwBasDpathWindowTimeService twBasDpathWindowTimeService;
	/**
	 *
	 * 出库记录 TT_WHM_STOCK_OUTBOUND
	 */
	@Autowired
	private TtWhmStockOutboundService ttWhmStockOutboundService;
	/**
	 *
	 * kitting消耗确认 TE_KITTING_WMS_CONFIRM
	 */
	@Autowired
	private TeKittingWmsConfirmService teKittingWmsConfirmService;
	/**
	 *
	 * 补货任务头表 TW_INV_PACKTRAN_HEADER
	 */
	@Autowired
	private TwInvPacktranHeaderService twInvPacktranHeaderService ;
	/**
	 *
	 * 补货任务明细TW_INV_PACKTRAN_DETAIL
	 */
	@Autowired
	private TwInvPacktranDetailService twInvPacktranDetailService;

	@Override
	public void excute() {

		// 【1】 job执行的时候，按补货路径分组，查出当前时间>=窗口时间 的补货路径记录
		List<WindowReplenishmentBean> list = twBasDpathWindowTimeService.queryWindowReplenishment();

		// 遍历每条满足时间的补货路径
		for (WindowReplenishmentBean dpathWindowTimeBean : list) {

			// 情况1：按出库：按照wms实际出库记录算消耗
			// 【2】根据补货路径id,查询出该补货路径下面的库位零件的消耗量。
			List<ImmediateReplenishmentByLibraryBean> partConsumptionBeanList = twInvPalMriService.queryOnePathPartsConsume(
					dpathWindowTimeBean.getTmBasDpathId());
			for (int j = 0; j < partConsumptionBeanList.size(); j++) {
				ImmediateReplenishmentByLibraryBean partConsumptionBean = partConsumptionBeanList.get(j);

				// 【3】遍历某条路径下面的所有的 库位零件消耗
				List<TwBasPackSkuQty> listTwBasPackSkuQty = twBasPackSkuQtyService.selectTwBasPackSkuQty(new Assist(
						Assist.andEq("tw_bas_pack_sku_qty.part_no_version", partConsumptionBean.getPartNoVersion()),
						Assist.andEq("tw_bas_pack_sku_qty.loc_no", partConsumptionBean.getLocNo()),
						Assist.andEq("tw_bas_pack_sku_qty.mri_status", "0")));
				Integer count = partConsumptionBean.getOutboundQty();
				if (listTwBasPackSkuQty.size() > 0) {
					for (TwBasPackSkuQty twBasPackSkuQty : listTwBasPackSkuQty) {
						count += twBasPackSkuQty.getStorageQty();
					}
				}

				// 1箱 = 消耗量/包装容量。 余数表数量>=1箱时，产生补货需求
				if (count / partConsumptionBean.getInboundPackQty() >= 1) {

					// 【4】：生成 补货任务头表 TW_INV_PACKTRAN_HEADER
					TwInvPacktranHeader twInvPacktranHeader = new TwInvPacktranHeader();
					// 任务状态（新任务0，任务确认1，任务完成2，任务部分完成3，关闭4）
					twInvPacktranHeader.setPacktranStatus("0");
					// 补货任务单打印状态（0打印1已打印）
					twInvPacktranHeader.setPacktranStatus("3");
					// 补货类型（1即时补货2按库存消耗补货3按累计消耗补货）
					twInvPacktranHeader.setPacktranType("1");
					// 补货路径
					twInvPacktranHeader.setRebRoad(dpathWindowTimeBean.getDpathNo());
					// 目的地
					twInvPacktranHeader.setDeliveryRec(dpathWindowTimeBean.getDeliveryRec());
					twInvPacktranHeader.setMarkStatus(1);
					twInvPacktranHeader.setCreateTime(new Date());
					twInvPacktranHeader.setTaskCreatetime(new Date());
					Map<String, Object> map = twInvPacktranHeaderService.insertNonEmptyTwInvPacktranHeader(
							twInvPacktranHeader);

					// 【5】：补货任务明细TW_INV_PACKTRAN_DETAIL
					TwInvPacktranDetail twInvPacktranDetail = new TwInvPacktranDetail();
					BeanUtils.copyProperties(partConsumptionBean, twInvPacktranDetail);
					twInvPacktranDetail.setTwInvPacktranHeaderId((int) map.get("twInvPacktranHeaderId"));
					// 零件号
					twInvPacktranDetail.setPartNoVersion(partConsumptionBean.getPartNoVersion());
					// 供应商编号
					twInvPacktranDetail.setSupplNo(partConsumptionBean.getSupplNo());
					// 零件中文名称
					twInvPacktranDetail.setPartNamec(partConsumptionBean.getPartNamec());
					// 零件基本单位
					twInvPacktranDetail.setBaseUnit(partConsumptionBean.getBaseUnit());
					// 物料目标仓库
					twInvPacktranDetail.setAfterPartWarehouse(partConsumptionBean.getAfterPartWarehouse());
					// 物料目标库区
					twInvPacktranDetail.setAfterPartDloc(partConsumptionBean.getAfterPartDloc());
					// 物料目标库位
					twInvPacktranDetail.setAfterPartLoc(partConsumptionBean.getAfterPartDloc());
					// 源仓库
					twInvPacktranDetail.setPFromWarehouseId(partConsumptionBean.getpFromWarehouseId());
					// 源库区
					twInvPacktranDetail.setPFromDlocId(partConsumptionBean.getpFromDlocId());
					// 源库位
					twInvPacktranDetail.setPFromLocId(partConsumptionBean.getpFromLocId());
					// 要求补货数量
					twInvPacktranDetail.setPrePacktranQty(count);
					// 要求补货包装数量
					twInvPacktranDetail.setPacktranPacknum(count / partConsumptionBean.getInboundPackQty());
					// 要求补货包装容量
					twInvPacktranDetail.setPacktranPackqty(partConsumptionBean.getInboundPackQty());
					// 补货类型 1:即时补货 , 2:按库存消耗补货 3:按累计消耗补货
					twInvPacktranDetail.setPacktranType("3");
					// 创建类型（自动/人工）
					twInvPacktranDetail.setTaskCreateType("0");
					// 补货任务行状态
					twInvPacktranDetail.setTaskStatue("0");
					// 指令创建时间
					twInvPacktranDetail.setTaskCreateTime(new Date());
					// 目的地
					twInvPacktranDetail.setDeliveryRec(dpathWindowTimeBean.getDeliveryRec());
					// 补货任务单号
					twInvPacktranDetail.setPacktranSheetNo((String) map.get("packtranSheetNo"));
					// 行号
					twInvPacktranDetail.setLineNo(j);
					// 是否需要分配库存(0:无来源库位需要分配|1：有来源库位，不需要分配)
					// 此处的逻辑，决定补货管理页面，是否需要分配库位的处理逻辑
					if (partConsumptionBean.getpFromLocId() != null && partConsumptionBean.getAfterPartDloc() != null) {
						twInvPacktranDetail.setAcallFlag("1");
					}
					if (partConsumptionBean.getpFromLocId() == null && partConsumptionBean.getAfterPartDloc() != null) {
						twInvPacktranDetail.setAcallFlag("0");
					}
					twInvPacktranDetail.setMarkStatus(1);
					twInvPacktranDetail.setCreateTime(new Date());
					twInvPacktranDetailService.insertTwInvPacktranDetail(twInvPacktranDetail);

					// 【6】产生补货需求，
					TwInvPalMri twInvPalMri = new TwInvPalMri();
					// 实际补货数量
					twInvPalMri.setActRepQty(0);
					// 补货任务单id
					twInvPalMri.setTwInvPacktranHeaderId((int) map.get("twInvPacktranHeaderId"));
					// 补货任务单明细id
					twInvPalMri.setTwInvPacktranDetailId(twInvPacktranDetail.getTwInvPacktranDetailId());
					// 补货任务单号
					twInvPalMri.setPacktranSheetNo((String) map.get("packtranSheetNo"));
					// 补货任务类型(1:即时补货;2:按库存消耗补货3按累计消耗补货)
					twInvPalMri.setPacktranType("3");
					// 零件号
					twInvPalMri.setPartNoVersion(partConsumptionBean.getPartNoVersion());
					// 供应商编号
					twInvPalMri.setSupplNo(partConsumptionBean.getSupplNo());
					// 零件中文名称
					twInvPalMri.setPartNamec(partConsumptionBean.getPartNamec());
					// 零件基本单位
					twInvPalMri.setBaseUnit(partConsumptionBean.getBaseUnit());
					// 补货任务目标仓库
					twInvPalMri.setAfterPartWarehouse(partConsumptionBean.getAfterPartWarehouse());
					// 补货任务目标 库区
					twInvPalMri.setAfterPartDloc(partConsumptionBean.getAfterPartDloc());
					// 补货任务目标库位
					twInvPalMri.setAfterPartLoc(partConsumptionBean.getAfterPartLoc());
					// 补货任务来源仓库
					twInvPalMri.setpFromWarehouseId(partConsumptionBean.getpFromWarehouseId());
					// 补货任务来源库区
					twInvPalMri.setpFromDlocId(partConsumptionBean.getpFromDlocId());
					// 补货任务来源库位
					twInvPalMri.setpFromLocId(partConsumptionBean.getpFromLocId());
					// 要求补货数量
					twInvPalMri.setPrePacktranQty(count);
					// 要求补货包装代码
					twInvPalMri.setPacktranPackno(partConsumptionBean.getPacktranPackno());
					// 要求补货包装数量(箱数)
					twInvPalMri.setPacktranPacknum(count / partConsumptionBean.getInboundPackQty());
					// 要求补货包装容量
					twInvPalMri.setPacktranPackqty(partConsumptionBean.getInboundPackQty());
					// 补货任务创建时间
					twInvPalMri.setPacktranCreatetime(new Date());
					// 补货任务需求状态(0:未组织;1已组织2:补货任务完成3:关闭)
					twInvPalMri.setMriStatue("1");
					// 货主 默认''qoros''
					twInvPalMri.setCustomerid(MesConstant.DELIVERY_UNIT_NO);
					// 收货地
					twInvPalMri.setDeliveryRec(partConsumptionBean.getDeliveryRec());
					// 补货路径
					twInvPalMri.setDpathNo(partConsumptionBean.getDpathNo());
					// 是否翻dolley
					twInvPalMri.setDolleyFlag(partConsumptionBean.getDolleyFlag());
					// 是否激活
					twInvPalMri.setMarkStatus(1);
					twInvPalMriService.insertNonEmptyTwInvPalMri(twInvPalMri);

					// 【7】 将已经使用的余量更新成 “已组织”的状态
					if (listTwBasPackSkuQty.size() > 0) {
						TwBasPackSkuQty twBasPackSkuQty3 = new TwBasPackSkuQty();
						twBasPackSkuQty3.setMriStatus("1");
						twBasPackSkuQtyService.updateNonEmptyTwBasPackSkuQty(twBasPackSkuQty3,
								new Assist(
										Assist.andEq("tw_bas_pack_sku_qty.part_no_version",
												partConsumptionBean.getPartNoVersion()),
										Assist.andEq("tw_bas_pack_sku_qty.loc_no", partConsumptionBean.getLocNo()),
										Assist.andEq("tw_bas_pack_sku_qty.mri_status", "0")));
					}

					// 【8】余数表重置：产生补货需求，对应的余数置为完成状态，另起一行记录
					// 余数
					Integer remainder = count % partConsumptionBean.getInboundPackQty();
					generateRemainder(twBasPackSkuQtyService, partConsumptionBean, remainder);

					// 【9】完成后需要将TT_WHM_STOCK_OUTBOUND补货组织状态置为完成
					TtWhmStockOutbound ttwhmstockoutbound = new TtWhmStockOutbound();
					ttwhmstockoutbound.setTtWhmStockOutboundId(partConsumptionBean.getTt_whm_stock_outbound_id());
					// 补货需求状态(0:未组织,1:已组织)
					ttwhmstockoutbound.setMriStatus("1");
					ttWhmStockOutboundService.updateNonEmptyTtWhmStockOutboundById(ttwhmstockoutbound);
				} else {
					System.out.println();
					System.err.println(
							"窗口补货-按累计消耗，此次定时任务零件号：" + partConsumptionBean.getPartNoVersion() + "，没有产生补货任务............");
					System.out.println();
				}
			} // 结束： 情况1 按出库 按照wms实际出库记录算消耗

			// 情况2：按请求 kitting消耗确认TE_KITTING_WMS_CONFIRM
			// 【3.1】根据补货路径id,查询出该补货路径下面的库位零件的kitting消耗量。
			List<ImmediateReplenishmentByRequestBean> partConsumptionByRequestBeanList = twInvPalMriService.queryTimelyReplenishmentByRequest(
					dpathWindowTimeBean.getTmBasDpathId());
			for (int i = 0; i < partConsumptionByRequestBeanList.size(); i++) {
				ImmediateReplenishmentByRequestBean partConsumptionByRequestBean = partConsumptionByRequestBeanList.get(
						i);

				// 【4.1】遍历某条路径下面的所有的 库位零件消耗 余数不止一条
				List<TwBasPackSkuQty> listTwBasPackSkuQty = twBasPackSkuQtyService.selectTwBasPackSkuQty(new Assist(
						Assist.andEq("tw_bas_pack_sku_qty.part_no_version",
								partConsumptionByRequestBean.getPartNoVersion()),
						Assist.andEq("tw_bas_pack_sku_qty.loc_no", partConsumptionByRequestBean.getLocNo()),
						Assist.andEq("tw_bas_pack_sku_qty.mri_status", "0")));
				Integer count = partConsumptionByRequestBean.getOutboundQty();
				if (listTwBasPackSkuQty.size() > 0) {
					TwBasPackSkuQty twBasPackSkuQty = listTwBasPackSkuQty.get(0);
					count += twBasPackSkuQty.getStorageQty();
				}

				// 【5.1】判断零件是否大于1箱，如果大于（余数表数量>=1箱)时，产生补货需求 。1箱 = 消耗量/包装容量。
				if (count / partConsumptionByRequestBean.getInboundPackQty() >= 1) {

					// 【6.1】：生成 补货任务头表 TW_INV_PACKTRAN_HEADER
					TwInvPacktranHeader twInvPacktranHeader = new TwInvPacktranHeader();
					// 任务状态（新任务0，任务确认1，任务完成2，任务部分完成3，关闭4）
					twInvPacktranHeader.setPacktranStatus("0");
					// 补货任务单打印状态（0打印1已打印）
					twInvPacktranHeader.setPacktranStatus("0");
					// 补货类型（1即时补货2按库存消耗补货3按累计消耗补货）
					twInvPacktranHeader.setPacktranType("3");
					// 补货路径
					twInvPacktranHeader.setRebRoad(dpathWindowTimeBean.getDpathNo());
					// 目的地
					twInvPacktranHeader.setDeliveryRec(dpathWindowTimeBean.getDeliveryRec());
					twInvPacktranHeader.setMarkStatus(1);
					twInvPacktranHeader.setCreateTime(new Date());
					twInvPacktranHeader.setTaskCreatetime(new Date());
					Map<String, Object> map = twInvPacktranHeaderService.insertNonEmptyTwInvPacktranHeader(
							twInvPacktranHeader);

					// 【7.1】：产生 补货任务明细TW_INV_PACKTRAN_DETAIL
					TwInvPacktranDetail twInvPacktranDetail = new TwInvPacktranDetail();
					BeanUtils.copyProperties(partConsumptionByRequestBean, twInvPacktranDetail);
					twInvPacktranDetail.setTwInvPacktranHeaderId((int) map.get("twInvPacktranHeaderId"));
					// 零件号
					twInvPacktranDetail.setPartNoVersion(partConsumptionByRequestBean.getPartNoVersion());
					// 供应商编号
					twInvPacktranDetail.setSupplNo(partConsumptionByRequestBean.getSupplNo());
					// 零件中文名称
					twInvPacktranDetail.setPartNamec(partConsumptionByRequestBean.getPartNamec());
					// 零件基本单位
					twInvPacktranDetail.setBaseUnit(partConsumptionByRequestBean.getBaseUnit());
					// 物料目标仓库
					twInvPacktranDetail.setAfterPartWarehouse(partConsumptionByRequestBean.getAfterPartWarehouse());
					// 物料目标库区
					twInvPacktranDetail.setAfterPartDloc(partConsumptionByRequestBean.getAfterPartDloc());
					// 物料目标库位
					twInvPacktranDetail.setAfterPartLoc(partConsumptionByRequestBean.getAfterPartDloc());
					// 源仓库
					twInvPacktranDetail.setPFromWarehouseId(partConsumptionByRequestBean.getpFromWarehouseId());
					// 源库区
					twInvPacktranDetail.setPFromDlocId(partConsumptionByRequestBean.getpFromDlocId());
					// 源库位
					twInvPacktranDetail.setPFromLocId(partConsumptionByRequestBean.getpFromLocId());
					// 要求补货数量
					twInvPacktranDetail.setPrePacktranQty(count);
					// 要求补货包装数量
					twInvPacktranDetail.setPacktranPacknum(count / partConsumptionByRequestBean.getInboundPackQty());
					// 要求补货包装容量
					twInvPacktranDetail.setPacktranPackqty(partConsumptionByRequestBean.getInboundPackQty());
					// 补货类型 1:即时补货 , 2:按库存消耗补货 3:按累计消耗补货
					twInvPacktranDetail.setPacktranType("3");
					// 创建类型（自动/人工）
					twInvPacktranDetail.setTaskCreateType("0");
					// 补货任务行状态
					twInvPacktranDetail.setTaskStatue("0");
					// 指令创建时间
					twInvPacktranDetail.setTaskCreateTime(new Date());
					// 目的地
					twInvPacktranDetail.setDeliveryRec(dpathWindowTimeBean.getDeliveryRec());
					// 补货任务单号
					twInvPacktranDetail.setPacktranSheetNo((String) map.get("packtranSheetNo"));
					// 行号
					twInvPacktranDetail.setLineNo(i + 1);
					// 此处的逻辑，决定补货管理页面，是否需要分配库位的处理逻辑
					if (partConsumptionByRequestBean.getpFromLocId() != null
							&& partConsumptionByRequestBean.getAfterPartDloc() != null) {
						twInvPacktranDetail.setAcallFlag("1");
					}
					if (partConsumptionByRequestBean.getpFromLocId() == null
							&& partConsumptionByRequestBean.getAfterPartDloc() != null) {
						twInvPacktranDetail.setAcallFlag("0");
					}
					twInvPacktranDetail.setMarkStatus(1);
					twInvPacktranDetail.setCreateTime(new Date());
					twInvPacktranDetailService.insertTwInvPacktranDetail(twInvPacktranDetail);

					// 【8.1】 往补货需求表(TW_INV_PAL_MRI)中，插入数据
					TwInvPalMri twInvPalMri = new TwInvPalMri();
					// 实际补货数量
					twInvPalMri.setActRepQty(0);
					// 补货任务类型(1:即时补货;2:按库存消耗补货3按累计消耗补货)
					twInvPalMri.setPacktranType("3");
					twInvPalMri.setPartNoVersion(partConsumptionByRequestBean.getPartNoVersion());
					// 供应商编号
					twInvPalMri.setSupplNo(partConsumptionByRequestBean.getSupplNo());
					// 零件中文名称
					twInvPalMri.setPartNamec(partConsumptionByRequestBean.getPartNamec());
					// 零件基本单位
					twInvPalMri.setBaseUnit(partConsumptionByRequestBean.getBaseUnit());
					// 补货任务目标仓库
					twInvPalMri.setAfterPartWarehouse(partConsumptionByRequestBean.getAfterPartWarehouse());
					// 补货任务目标库区
					twInvPalMri.setAfterPartDloc(partConsumptionByRequestBean.getAfterPartDloc());
					// 补货任务目标库位
					twInvPalMri.setAfterPartLoc(partConsumptionByRequestBean.getAfterPartLoc());
					// 补货任务来源仓库
					twInvPalMri.setpFromWarehouseId(partConsumptionByRequestBean.getpFromWarehouseId());
					// 补货任务来源库区
					twInvPalMri.setpFromDlocId(partConsumptionByRequestBean.getpFromDlocId());
					// 补货任务来源库位
					twInvPalMri.setpFromLocId(partConsumptionByRequestBean.getpFromLocId());
					// 要求补货数量
					twInvPalMri.setPrePacktranQty(count);
					// 要求补货包装代码
					twInvPalMri.setPacktranPackno(partConsumptionByRequestBean.getPacktranPackno());
					// 要求补货包装数量(箱数)
					twInvPalMri.setPacktranPacknum(count / partConsumptionByRequestBean.getInboundPackQty());
					// 要求补货包装容量
					twInvPalMri.setPacktranPackqty(partConsumptionByRequestBean.getInboundPackQty());
					// 补货任务创建时间
					twInvPalMri.setPacktranCreatetime(new Date());
					// 补货任务需求状态(0:未组织;1已组织2:补货任务完成3:关闭)
					twInvPalMri.setMriStatue("1");
					// 货主 默认''qoros''
					twInvPalMri.setCustomerid(MesConstant.DELIVERY_UNIT_NO);
					// 收货地
					twInvPalMri.setDeliveryRec(partConsumptionByRequestBean.getDeliveryRec());
					// 补货路径
					twInvPalMri.setDpathNo(partConsumptionByRequestBean.getDpathNo());
					// 是否翻dolley
					twInvPalMri.setDolleyFlag(partConsumptionByRequestBean.getDolleyFlag());
					// 是否激活
					twInvPalMri.setMarkStatus(1);
					// 创建时间
					twInvPalMri.setCreateUser(SpringWebUtils.getRequestUser());
					// 企业代码
					twInvPalMri.setCompanyCode(SpringWebUtils.getRequestCompany());
					twInvPalMriService.insertNonEmptyTwInvPalMri(twInvPalMri);

					// 【9.1】 将已经使用的余量更新成 “已组织”的状态
					if (listTwBasPackSkuQty.size() > 0) {
						TwBasPackSkuQty twBasPackSkuQty3 = new TwBasPackSkuQty();
						twBasPackSkuQty3.setMriStatus("1");
						twBasPackSkuQtyService.updateNonEmptyTwBasPackSkuQty(twBasPackSkuQty3, new Assist(
								Assist.andEq("tw_bas_pack_sku_qty.part_no_version",
										partConsumptionByRequestBean.getPartNoVersion()),
								Assist.andEq("tw_bas_pack_sku_qty.loc_no", partConsumptionByRequestBean.getLocNo()),
								Assist.andEq("tw_bas_pack_sku_qty.mri_status", "0")));
					}

					// 【10.1】余数表重置：产生补货需求，对应的余数置为完成状态，另起一行记录
					// 余数
					Integer remainder = count % partConsumptionByRequestBean.getInboundPackQty();
					if (remainder > 0) {
						TwBasPackSkuQty twBasPackSkuQty = new TwBasPackSkuQty();
						// 零件号
						twBasPackSkuQty.setPartNoVersion(partConsumptionByRequestBean.getPartNoVersion());
						// 库位
						twBasPackSkuQty.setLocNo(partConsumptionByRequestBean.getLocNo());
						// 余量
						twBasPackSkuQty.setStorageQty(remainder);
						// 组织状态0未组织1已组织
						twBasPackSkuQty.setMriStatus("0");
						twBasPackSkuQty.setCreateTime(new Date());
						twBasPackSkuQtyService.insertTwBasPackSkuQty(twBasPackSkuQty);
					}

					// 【11.1】完成后需要将TE_KITTING_WMS_CONFIRM补货组织状态置为完成
					TeKittingWmsConfirm tekittingwmsconfirm = new TeKittingWmsConfirm();
					tekittingwmsconfirm.setTeKittingWmsConfirmId(
							partConsumptionByRequestBean.getTe_kitting_wms_confirm_id());
					// 补货需求状态(0:未组织,1:已组织)
					tekittingwmsconfirm.setMriStatus("1");
					teKittingWmsConfirmService.updateNonEmptyTeKittingWmsConfirmById(tekittingwmsconfirm);
				} else {
					System.out.println();
					System.err.println("窗口补货-按累计消耗，此次定时任务零件号：" + partConsumptionByRequestBean.getPartNoVersion()
							+ "，没有产生补货任务............");
					System.out.println();
				}
			}
			// 结束： 情况2 按请求 kitting消耗确认TE_KITTING_WMS_CONFIRM
		}
	}

	static void generateRemainder(TwBasPackSkuQtyService twBasPackSkuQtyService,
			ImmediateReplenishmentByLibraryBean partConsumptionBean, Integer remainder) {
		if (remainder > 0) {
			TwBasPackSkuQty twBasPackSkuQty = new TwBasPackSkuQty();
			// 零件号
			twBasPackSkuQty.setPartNoVersion(partConsumptionBean.getPartNoVersion());
			// 库位
			twBasPackSkuQty.setLocNo(partConsumptionBean.getLocNo());
			// 余量
			twBasPackSkuQty.setStorageQty(remainder);
			// 组织状态0未组织1已组织
			twBasPackSkuQty.setMriStatus("0");
			twBasPackSkuQty.setCreateTime(new Date());
			twBasPackSkuQtyService.insertTwBasPackSkuQty(twBasPackSkuQty);
		}
	}

}
